home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1998 November / Freeware November 1998.img / dist / fw_elisp-manual-19.idb / usr / freeware / info / elisp-14.z / elisp-14 (.txt)
GNU Info File  |  1998-05-26  |  48KB  |  866 lines

  1. This is Info file elisp, produced by Makeinfo-1.63 from the input file
  2. elisp.texi.
  3.    This version is the edition 2.4.2 of the GNU Emacs Lisp Reference
  4. Manual.  It corresponds to Emacs Version 19.34.
  5.    Published by the Free Software Foundation 59 Temple Place, Suite 330
  6. Boston, MA  02111-1307  USA
  7.    Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1996 Free Software
  8. Foundation, Inc.
  9.    Permission is granted to make and distribute verbatim copies of this
  10. manual provided the copyright notice and this permission notice are
  11. preserved on all copies.
  12.    Permission is granted to copy and distribute modified versions of
  13. this manual under the conditions for verbatim copying, provided that the
  14. entire resulting derived work is distributed under the terms of a
  15. permission notice identical to this one.
  16.    Permission is granted to copy and distribute translations of this
  17. manual into another language, under the above conditions for modified
  18. versions, except that this permission notice may be stated in a
  19. translation approved by the Foundation.
  20.    Permission is granted to copy and distribute modified versions of
  21. this manual under the conditions for verbatim copying, provided also
  22. that the section entitled "GNU General Public License" is included
  23. exactly as in the original, and provided that the entire resulting
  24. derived work is distributed under the terms of a permission notice
  25. identical to this one.
  26.    Permission is granted to copy and distribute translations of this
  27. manual into another language, under the above conditions for modified
  28. versions, except that the section entitled "GNU General Public License"
  29. may be included in a translation approved by the Free Software
  30. Foundation instead of in the original English.
  31. File: elisp,  Node: Minibuffer History,  Next: Completion,  Prev: Object from Minibuffer,  Up: Minibuffers
  32. Minibuffer History
  33. ==================
  34.    A "minibuffer history list" records previous minibuffer inputs so
  35. the user can reuse them conveniently.  A history list is actually a
  36. symbol, not a list; it is a variable whose value is a list of strings
  37. (previous inputs), most recent first.
  38.    There are many separate history lists, used for different kinds of
  39. inputs.  It's the Lisp programmer's job to specify the right history
  40. list for each use of the minibuffer.
  41.    The basic minibuffer input functions `read-from-minibuffer' and
  42. `completing-read' both accept an optional argument named HIST which is
  43. how you specify the history list.  Here are the possible values:
  44. VARIABLE
  45.      Use VARIABLE (a symbol) as the history list.
  46. (VARIABLE . STARTPOS)
  47.      Use VARIABLE (a symbol) as the history list, and assume that the
  48.      initial history position is STARTPOS (an integer, counting from
  49.      zero which specifies the most recent element of the history).
  50.      If you specify STARTPOS, then you should also specify that element
  51.      of the history as the initial minibuffer contents, for consistency.
  52.    If you don't specify HIST, then the default history list
  53. `minibuffer-history' is used.  For other standard history lists, see
  54. below.  You can also create your own history list variable; just
  55. initialize it to `nil' before the first use.
  56.    Both `read-from-minibuffer' and `completing-read' add new elements
  57. to the history list automatically, and provide commands to allow the
  58. user to reuse items on the list.  The only thing your program needs to
  59. do to use a history list is to initialize it and to pass its name to
  60. the input functions when you wish.  But it is safe to modify the list
  61. by hand when the minibuffer input functions are not using it.
  62.  - Variable: minibuffer-history
  63.      The default history list for minibuffer history input.
  64.  - Variable: query-replace-history
  65.      A history list for arguments to `query-replace' (and similar
  66.      arguments to other commands).
  67.  - Variable: file-name-history
  68.      A history list for file name arguments.
  69.  - Variable: regexp-history
  70.      A history list for regular expression arguments.
  71.  - Variable: extended-command-history
  72.      A history list for arguments that are names of extended commands.
  73.  - Variable: shell-command-history
  74.      A history list for arguments that are shell commands.
  75.  - Variable: read-expression-history
  76.      A history list for arguments that are Lisp expressions to evaluate.
  77. File: elisp,  Node: Completion,  Next: Yes-or-No Queries,  Prev: Minibuffer History,  Up: Minibuffers
  78. Completion
  79. ==========
  80.    "Completion" is a feature that fills in the rest of a name starting
  81. from an abbreviation for it.  Completion works by comparing the user's
  82. input against a list of valid names and determining how much of the
  83. name is determined uniquely by what the user has typed.  For example,
  84. when you type `C-x b' (`switch-to-buffer') and then type the first few
  85. letters of the name of the buffer to which you wish to switch, and then
  86. type TAB (`minibuffer-complete'), Emacs extends the name as far as it
  87.    Standard Emacs commands offer completion for names of symbols, files,
  88. buffers, and processes; with the functions in this section, you can
  89. implement completion for other kinds of names.
  90.    The `try-completion' function is the basic primitive for completion:
  91. it returns the longest determined completion of a given initial string,
  92. with a given set of strings to match against.
  93.    The function `completing-read' provides a higher-level interface for
  94. completion.  A call to `completing-read' specifies how to determine the
  95. list of valid names.  The function then activates the minibuffer with a
  96. local keymap that binds a few keys to commands useful for completion.
  97. Other functions provide convenient simple interfaces for reading
  98. certain kinds of names with completion.
  99. * Menu:
  100. * Basic Completion::       Low-level functions for completing strings.
  101.                              (These are too low level to use the minibuffer.)
  102. * Minibuffer Completion::  Invoking the minibuffer with completion.
  103. * Completion Commands::    Minibuffer commands that do completion.
  104. * High-Level Completion::  Convenient special cases of completion
  105.                              (reading buffer name, file name, etc.)
  106. * Reading File Names::     Using completion to read file names.
  107. * Programmed Completion::  Finding the completions for a given file name.
  108. File: elisp,  Node: Basic Completion,  Next: Minibuffer Completion,  Up: Completion
  109. Basic Completion Functions
  110. --------------------------
  111.    The two functions `try-completion' and `all-completions' have
  112. nothing in themselves to do with minibuffers.  We describe them in this
  113. chapter so as to keep them near the higher-level completion features
  114. that do use the minibuffer.
  115.  - Function: try-completion STRING COLLECTION &optional PREDICATE
  116.      This function returns the longest common substring of all possible
  117.      completions of STRING in COLLECTION.  The value of COLLECTION must
  118.      be an alist, an obarray, or a function that implements a virtual
  119.      set of strings (see below).
  120.      Completion compares STRING against each of the permissible
  121.      completions specified by COLLECTION; if the beginning of the
  122.      permissible completion equals STRING, it matches.  If no
  123.      permissible completions match, `try-completion' returns `nil'.  If
  124.      only one permissible completion matches, and the match is exact,
  125.      then `try-completion' returns `t'.  Otherwise, the value is the
  126.      longest initial sequence common to all the permissible completions
  127.      that match.
  128.      If COLLECTION is an alist (*note Association Lists::.), the CARs
  129.      of the alist elements form the set of permissible completions.
  130.      If COLLECTION is an obarray (*note Creating Symbols::.), the names
  131.      of all symbols in the obarray form the set of permissible
  132.      completions.  The global variable `obarray' holds an obarray
  133.      containing the names of all interned Lisp symbols.
  134.      Note that the only valid way to make a new obarray is to create it
  135.      empty and then add symbols to it one by one using `intern'.  Also,
  136.      you cannot intern a given symbol in more than one obarray.
  137.      If the argument PREDICATE is non-`nil', then it must be a function
  138.      of one argument.  It is used to test each possible match, and the
  139.      match is accepted only if PREDICATE returns non-`nil'.  The
  140.      argument given to PREDICATE is either a cons cell from the alist
  141.      (the CAR of which is a string) or else it is a symbol (*not* a
  142.      symbol name) from the obarray.
  143.      You can also use a symbol that is a function as COLLECTION.  Then
  144.      the function is solely responsible for performing completion;
  145.      `try-completion' returns whatever this function returns.  The
  146.      function is called with three arguments: STRING, PREDICATE and
  147.      `nil'.  (The reason for the third argument is so that the same
  148.      function can be used in `all-completions' and do the appropriate
  149.      thing in either case.)  *Note Programmed Completion::.
  150.      In the first of the following examples, the string `foo' is
  151.      matched by three of the alist CARs.  All of the matches begin with
  152.      the characters `fooba', so that is the result.  In the second
  153.      example, there is only one possible match, and it is exact, so the
  154.      value is `t'.
  155.           (try-completion
  156.            "foo"
  157.            '(("foobar1" 1) ("barfoo" 2) ("foobaz" 3) ("foobar2" 4)))
  158.                => "fooba"
  159.           (try-completion "foo" '(("barfoo" 2) ("foo" 3)))
  160.                => t
  161.      In the following example, numerous symbols begin with the
  162.      characters `forw', and all of them begin with the word `forward'.
  163.      In most of the symbols, this is followed with a `-', but not in
  164.      all, so no more than `forward' can be completed.
  165.           (try-completion "forw" obarray)
  166.                => "forward"
  167.      Finally, in the following example, only two of the three possible
  168.      matches pass the predicate `test' (the string `foobaz' is too
  169.      short).  Both of those begin with the string `foobar'.
  170.           (defun test (s)
  171.             (> (length (car s)) 6))
  172.                => test
  173.           (try-completion
  174.            "foo"
  175.            '(("foobar1" 1) ("barfoo" 2) ("foobaz" 3) ("foobar2" 4))
  176.            'test)
  177.                => "foobar"
  178.  - Function: all-completions STRING COLLECTION &optional PREDICATE
  179.           NOSPACE
  180.      This function returns a list of all possible completions of
  181.      STRING.  The parameters to this function are the same as to
  182.      `try-completion'.
  183.      If COLLECTION is a function, it is called with three arguments:
  184.      STRING, PREDICATE and `t'; then `all-completions' returns whatever
  185.      the function returns.  *Note Programmed Completion::.
  186.      If NOSPACE is non-`nil', completions that start with a space are
  187.      ignored unless STRING also starts with a space.
  188.      Here is an example, using the function `test' shown in the example
  189.      for `try-completion':
  190.           (defun test (s)
  191.             (> (length (car s)) 6))
  192.                => test
  193.           (all-completions
  194.            "foo"
  195.            '(("foobar1" 1) ("barfoo" 2) ("foobaz" 3) ("foobar2" 4))
  196.            'test)
  197.                => ("foobar1" "foobar2")
  198.  - Variable: completion-ignore-case
  199.      If the value of this variable is non-`nil', Emacs does not
  200.      consider case significant in completion.
  201. File: elisp,  Node: Minibuffer Completion,  Next: Completion Commands,  Prev: Basic Completion,  Up: Completion
  202. Completion and the Minibuffer
  203. -----------------------------
  204.    This section describes the basic interface for reading from the
  205. minibuffer with completion.
  206.  - Function: completing-read PROMPT COLLECTION &optional PREDICATE
  207.           REQUIRE-MATCH INITIAL HIST
  208.      This function reads a string in the minibuffer, assisting the user
  209.      by providing completion.  It activates the minibuffer with prompt
  210.      PROMPT, which must be a string.  If INITIAL is non-`nil',
  211.      `completing-read' inserts it into the minibuffer as part of the
  212.      input.  Then it allows the user to edit the input, providing
  213.      several commands to attempt completion.
  214.      The actual completion is done by passing COLLECTION and PREDICATE
  215.      to the function `try-completion'.  This happens in certain
  216.      commands bound in the local keymaps used for completion.
  217.      If REQUIRE-MATCH is `t', the usual minibuffer exit commands won't
  218.      exit unless the input completes to an element of COLLECTION.  If
  219.      REQUIRE-MATCH is neither `nil' nor `t', then the exit commands
  220.      won't exit unless the input typed is itself an element of
  221.      COLLECTION.  If REQUIRE-MATCH is `nil', the exit commands work
  222.      regardless of the input in the minibuffer.
  223.      The user can exit with null input by typing RET with an empty
  224.      minibuffer.  Then `completing-read' returns `""'.  This is how the
  225.      user requests whatever default the command uses for the value being
  226.      read.  The user can return using RET in this way regardless of the
  227.      value of REQUIRE-MATCH, and regardless of whether the empty string
  228.      is included in COLLECTION.
  229.      The function `completing-read' works by calling `read-minibuffer'.
  230.      It uses `minibuffer-local-completion-map' as the keymap if
  231.      REQUIRE-MATCH is `nil', and uses `minibuffer-local-must-match-map'
  232.      if REQUIRE-MATCH is non-`nil'.  *Note Completion Commands::.
  233.      The argument HIST specifies which history list variable to use for
  234.      saving the input and for minibuffer history commands.  It defaults
  235.      to `minibuffer-history'.  *Note Minibuffer History::.
  236.      Completion ignores case when comparing the input against the
  237.      possible matches, if the built-in variable
  238.      `completion-ignore-case' is non-`nil'.  *Note Basic Completion::.
  239.      Here's an example of using `completing-read':
  240.           (completing-read
  241.            "Complete a foo: "
  242.            '(("foobar1" 1) ("barfoo" 2) ("foobaz" 3) ("foobar2" 4))
  243.            nil t "fo")
  244.           ;; After evaluation of the preceding expression,
  245.           ;;   the following appears in the minibuffer:
  246.           
  247.           ---------- Buffer: Minibuffer ----------
  248.           Complete a foo: fo-!-
  249.           ---------- Buffer: Minibuffer ----------
  250.      If the user then types `DEL DEL b RET', `completing-read' returns
  251.      `barfoo'.
  252.      The `completing-read' function binds three variables to pass
  253.      information to the commands that actually do completion.  These
  254.      variables are `minibuffer-completion-table',
  255.      `minibuffer-completion-predicate' and
  256.      `minibuffer-completion-confirm'.  For more information about them,
  257.      see *Note Completion Commands::.
  258. File: elisp,  Node: Completion Commands,  Next: High-Level Completion,  Prev: Minibuffer Completion,  Up: Completion
  259. Minibuffer Commands That Do Completion
  260. --------------------------------------
  261.    This section describes the keymaps, commands and user options used in
  262. the minibuffer to do completion.
  263.  - Variable: minibuffer-local-completion-map
  264.      `completing-read' uses this value as the local keymap when an
  265.      exact match of one of the completions is not required.  By
  266.      default, this keymap makes the following bindings:
  267.     `?'
  268.           `minibuffer-completion-help'
  269.     SPC
  270.           `minibuffer-complete-word'
  271.     TAB
  272.           `minibuffer-complete'
  273.      with other characters bound as in `minibuffer-local-map' (*note
  274.      Text from Minibuffer::.).
  275.  - Variable: minibuffer-local-must-match-map
  276.      `completing-read' uses this value as the local keymap when an
  277.      exact match of one of the completions is required.  Therefore, no
  278.      keys are bound to `exit-minibuffer', the command that exits the
  279.      minibuffer unconditionally.  By default, this keymap makes the
  280.      following bindings:
  281.     `?'
  282.           `minibuffer-completion-help'
  283.     SPC
  284.           `minibuffer-complete-word'
  285.     TAB
  286.           `minibuffer-complete'
  287.     LFD
  288.           `minibuffer-complete-and-exit'
  289.     RET
  290.           `minibuffer-complete-and-exit'
  291.      with other characters bound as in `minibuffer-local-map'.
  292.  - Variable: minibuffer-completion-table
  293.      The value of this variable is the alist or obarray used for
  294.      completion in the minibuffer.  This is the global variable that
  295.      contains what `completing-read' passes to `try-completion'.  It is
  296.      used by minibuffer completion commands such as
  297.      `minibuffer-complete-word'.
  298.  - Variable: minibuffer-completion-predicate
  299.      This variable's value is the predicate that `completing-read'
  300.      passes to `try-completion'.  The variable is also used by the other
  301.      minibuffer completion functions.
  302.  - Command: minibuffer-complete-word
  303.      This function completes the minibuffer contents by at most a single
  304.      word.  Even if the minibuffer contents have only one completion,
  305.      `minibuffer-complete-word' does not add any characters beyond the
  306.      first character that is not a word constituent.  *Note Syntax
  307.      Tables::.
  308.  - Command: minibuffer-complete
  309.      This function completes the minibuffer contents as far as possible.
  310.  - Command: minibuffer-complete-and-exit
  311.      This function completes the minibuffer contents, and exits if
  312.      confirmation is not required, i.e., if
  313.      `minibuffer-completion-confirm' is `nil'.  If confirmation *is*
  314.      required, it is given by repeating this command immediately--the
  315.      command is programmed to work without confirmation when run twice
  316.      in succession.
  317.  - Variable: minibuffer-completion-confirm
  318.      When the value of this variable is non-`nil', Emacs asks for
  319.      confirmation of a completion before exiting the minibuffer.  The
  320.      function `minibuffer-complete-and-exit' checks the value of this
  321.      variable before it exits.
  322.  - Command: minibuffer-completion-help
  323.      This function creates a list of the possible completions of the
  324.      current minibuffer contents.  It works by calling `all-completions'
  325.      using the value of the variable `minibuffer-completion-table' as
  326.      the COLLECTION argument, and the value of
  327.      `minibuffer-completion-predicate' as the PREDICATE argument.  The
  328.      list of completions is displayed as text in a buffer named
  329.      `*Completions*'.
  330.  - Function: display-completion-list COMPLETIONS
  331.      This function displays COMPLETIONS to the stream in
  332.      `standard-output', usually a buffer.  (*Note Read and Print::, for
  333.      more information about streams.)  The argument COMPLETIONS is
  334.      normally a list of completions just returned by `all-completions',
  335.      but it does not have to be.  Each element may be a symbol or a
  336.      string, either of which is simply printed, or a list of two
  337.      strings, which is printed as if the strings were concatenated.
  338.      This function is called by `minibuffer-completion-help'.  The most
  339.      common way to use it is together with
  340.      `with-output-to-temp-buffer', like this:
  341.           (with-output-to-temp-buffer "*Completions*"
  342.             (display-completion-list
  343.               (all-completions (buffer-string) my-alist)))
  344.  - User Option: completion-auto-help
  345.      If this variable is non-`nil', the completion commands
  346.      automatically display a list of possible completions whenever
  347.      nothing can be completed because the next character is not
  348.      uniquely determined.
  349. File: elisp,  Node: High-Level Completion,  Next: Reading File Names,  Prev: Completion Commands,  Up: Completion
  350. High-Level Completion  Functions
  351. --------------------------------
  352.    This section describes the higher-level convenient functions for
  353. reading certain sorts of names with completion.
  354.    In most cases, you should not call these functions in the middle of a
  355. Lisp function.  When possible, do all minibuffer input as part of
  356. reading the arguments for a command, in the `interactive' spec.  *Note
  357. Defining Commands::.
  358.  - Function: read-buffer PROMPT &optional DEFAULT EXISTING
  359.      This function reads the name of a buffer and returns it as a
  360.      string.  The argument DEFAULT is the default name to use, the
  361.      value to return if the user exits with an empty minibuffer.  If
  362.      non-`nil', it should be a string or a buffer.  It is mentioned in
  363.      the prompt, but is not inserted in the minibuffer as initial input.
  364.      If EXISTING is non-`nil', then the name specified must be that of
  365.      an existing buffer.  The usual commands to exit the minibuffer do
  366.      not exit if the text is not valid, and RET does completion to
  367.      attempt to find a valid name.  (However, DEFAULT is not checked
  368.      for validity; it is returned, whatever it is, if the user exits
  369.      with the minibuffer empty.)
  370.      In the following example, the user enters `minibuffer.t', and then
  371.      types RET.  The argument EXISTING is `t', and the only buffer name
  372.      starting with the given input is `minibuffer.texi', so that name
  373.      is the value.
  374.           (read-buffer "Buffer name? " "foo" t)
  375.           ;; After evaluation of the preceding expression,
  376.           ;;   the following prompt appears,
  377.           ;;   with an empty minibuffer:
  378.           
  379.           ---------- Buffer: Minibuffer ----------
  380.           Buffer name? (default foo) -!-
  381.           ---------- Buffer: Minibuffer ----------
  382.           
  383.           ;; The user types `minibuffer.t RET'.
  384.                => "minibuffer.texi"
  385.  - Function: read-command PROMPT
  386.      This function reads the name of a command and returns it as a Lisp
  387.      symbol.  The argument PROMPT is used as in `read-from-minibuffer'.
  388.      Recall that a command is anything for which `commandp' returns
  389.      `t', and a command name is a symbol for which `commandp' returns
  390.      `t'.  *Note Interactive Call::.
  391.           (read-command "Command name? ")
  392.           
  393.           ;; After evaluation of the preceding expression,
  394.           ;;   the following prompt appears with an empty minibuffer:
  395.           
  396.           ---------- Buffer: Minibuffer ----------
  397.           Command name?
  398.           ---------- Buffer: Minibuffer ----------
  399.      If the user types `forward-c RET', then this function returns
  400.      `forward-char'.
  401.      The `read-command' function is a simplified interface to
  402.      `completing-read'.  It uses the variable `obarray' so as to
  403.      complete in the set of extant Lisp symbols, and it uses the
  404.      `commandp' predicate so as to accept only command names:
  405.           (read-command PROMPT)
  406.           ==
  407.           (intern (completing-read PROMPT obarray
  408.                                    'commandp t nil))
  409.  - Function: read-variable PROMPT
  410.      This function reads the name of a user variable and returns it as a
  411.      symbol.
  412.           (read-variable "Variable name? ")
  413.           
  414.           ;; After evaluation of the preceding expression,
  415.           ;;   the following prompt appears,
  416.           ;;   with an empty minibuffer:
  417.           
  418.           ---------- Buffer: Minibuffer ----------
  419.           Variable name? -!-
  420.           ---------- Buffer: Minibuffer ----------
  421.      If the user then types `fill-p RET', `read-variable' returns
  422.      `fill-prefix'.
  423.      This function is similar to `read-command', but uses the predicate
  424.      `user-variable-p' instead of `commandp':
  425.           (read-variable PROMPT)
  426.           ==
  427.           (intern
  428.            (completing-read PROMPT obarray
  429.                             'user-variable-p t nil))
  430. File: elisp,  Node: Reading File Names,  Next: Programmed Completion,  Prev: High-Level Completion,  Up: Completion
  431. Reading File Names
  432. ------------------
  433.    Here is another high-level completion function, designed for reading
  434. a file name.  It provides special features including automatic insertion
  435. of the default directory.
  436.  - Function: read-file-name PROMPT &optional DIRECTORY DEFAULT EXISTING
  437.           INITIAL
  438.      This function reads a file name in the minibuffer, prompting with
  439.      PROMPT and providing completion.  If DEFAULT is non-`nil', then
  440.      the function returns DEFAULT if the user just types RET.  DEFAULT
  441.      is not checked for validity; it is returned, whatever it is, if
  442.      the user exits with the minibuffer empty.
  443.      If EXISTING is non-`nil', then the user must specify the name of
  444.      an existing file; RET performs completion to make the name valid
  445.      if possible, and then refuses to exit if it is not valid.  If the
  446.      value of EXISTING is neither `nil' nor `t', then RET also requires
  447.      confirmation after completion.  If EXISTING is `nil', then the
  448.      name of a nonexistent file is acceptable.
  449.      The argument DIRECTORY specifies the directory to use for
  450.      completion of relative file names.  If `insert-default-directory'
  451.      is non-`nil', DIRECTORY is also inserted in the minibuffer as
  452.      initial input.  It defaults to the current buffer's value of
  453.      `default-directory'.
  454.      If you specify INITIAL, that is an initial file name to insert in
  455.      the buffer (after with DIRECTORY, if that is inserted).  In this
  456.      case, point goes at the beginning of INITIAL.  The default for
  457.      INITIAL is `nil'--don't insert any file name.  To see what INITIAL
  458.      does, try the command `C-x C-v'.
  459.      Here is an example:
  460.           (read-file-name "The file is ")
  461.           
  462.           ;; After evaluation of the preceding expression,
  463.           ;;   the following appears in the minibuffer:
  464.           
  465.           ---------- Buffer: Minibuffer ----------
  466.           The file is /gp/gnu/elisp/-!-
  467.           ---------- Buffer: Minibuffer ----------
  468.      Typing `manual TAB' results in the following:
  469.           ---------- Buffer: Minibuffer ----------
  470.           The file is /gp/gnu/elisp/manual.texi-!-
  471.           ---------- Buffer: Minibuffer ----------
  472.      If the user types RET, `read-file-name' returns the file name as
  473.      the string `"/gp/gnu/elisp/manual.texi"'.
  474.  - User Option: insert-default-directory
  475.      This variable is used by `read-file-name'.  Its value controls
  476.      whether `read-file-name' starts by placing the name of the default
  477.      directory in the minibuffer, plus the initial file name if any.
  478.      If the value of this variable is `nil', then `read-file-name' does
  479.      not place any initial input in the minibuffer (unless you specify
  480.      initial input with the INITIAL argument).  In that case, the
  481.      default directory is still used for completion of relative file
  482.      names, but is not displayed.
  483.      For example:
  484.           ;; Here the minibuffer starts out with the default directory.
  485.           (let ((insert-default-directory t))
  486.             (read-file-name "The file is "))
  487.           
  488.           ---------- Buffer: Minibuffer ----------
  489.           The file is ~lewis/manual/-!-
  490.           ---------- Buffer: Minibuffer ----------
  491.           
  492.           ;; Here the minibuffer is empty and only the prompt
  493.           ;;   appears on its line.
  494.           (let ((insert-default-directory nil))
  495.             (read-file-name "The file is "))
  496.           
  497.           ---------- Buffer: Minibuffer ----------
  498.           The file is -!-
  499.           ---------- Buffer: Minibuffer ----------
  500. File: elisp,  Node: Programmed Completion,  Prev: Reading File Names,  Up: Completion
  501. Programmed Completion
  502. ---------------------
  503.    Sometimes it is not possible to create an alist or an obarray
  504. containing all the intended possible completions.  In such a case, you
  505. can supply your own function to compute the completion of a given
  506. string.  This is called "programmed completion".
  507.    To use this feature, pass a symbol with a function definition as the
  508. COLLECTION argument to `completing-read'.  The function
  509. `completing-read' arranges to pass your completion function along to
  510. `try-completion' and `all-completions', which will then let your
  511. function do all the work.
  512.    The completion function should accept three arguments:
  513.    * The string to be completed.
  514.    * The predicate function to filter possible matches, or `nil' if
  515.      none.  Your function should call the predicate for each possible
  516.      match, and ignore the possible match if the predicate returns
  517.      `nil'.
  518.    * A flag specifying the type of operation.
  519.    There are three flag values for three operations:
  520.    * `nil' specifies `try-completion'.  The completion function should
  521.      return the completion of the specified string, or `t' if the
  522.      string is a unique and exact match already, or `nil' if the string
  523.      matches no possibility.
  524.      If the string is an exact match for one possibility, but also
  525.      matches other longer possibilities, the function shuold return the
  526.      string, not `t'.
  527.    * `t' specifies `all-completions'.  The completion function should
  528.      return a list of all possible completions of the specified string.
  529.    * `lambda' specifies a test for an exact match.  The completion
  530.      function should return `t' if the specified string is an exact
  531.      match for some possibility; `nil' otherwise.
  532.    It would be consistent and clean for completion functions to allow
  533. lambda expressions (lists that are functions) as well as function
  534. symbols as COLLECTION, but this is impossible.  Lists as completion
  535. tables are already assigned another meaning--as alists.  It would be
  536. unreliable to fail to handle an alist normally because it is also a
  537. possible function.  So you must arrange for any function you wish to
  538. use for completion to be encapsulated in a symbol.
  539.    Emacs uses programmed completion when completing file names.  *Note
  540. File Name Completion::.
  541. File: elisp,  Node: Yes-or-No Queries,  Next: Multiple Queries,  Prev: Completion,  Up: Minibuffers
  542. Yes-or-No Queries
  543. =================
  544.    This section describes functions used to ask the user a yes-or-no
  545. question.  The function `y-or-n-p' can be answered with a single
  546. character; it is useful for questions where an inadvertent wrong answer
  547. will not have serious consequences.  `yes-or-no-p' is suitable for more
  548. momentous questions, since it requires three or four characters to
  549. answer.
  550.    If either of these functions is called in a command that was invoked
  551. using the mouse--more precisely, if `last-nonmenu-event' (*note Command
  552. Loop Info::.) is either `nil' or a list--then it uses a dialog box or
  553. pop-up menu to ask the question.  Otherwise, it uses keyboard input.
  554. You can force use of the mouse or use of keyboard input by binding
  555. `last-nonmenu-event' to a suitable value around the call.
  556.    Strictly speaking, `yes-or-no-p' uses the minibuffer and `y-or-n-p'
  557. does not; but it seems best to describe them together.
  558.  - Function: y-or-n-p PROMPT
  559.      This function asks the user a question, expecting input in the echo
  560.      area.  It returns `t' if the user types `y', `nil' if the user
  561.      types `n'.  This function also accepts SPC to mean yes and DEL to
  562.      mean no.  It accepts `C-]' to mean "quit", like `C-g', because the
  563.      question might look like a minibuffer and for that reason the user
  564.      might try to use `C-]' to get out.  The answer is a single
  565.      character, with no RET needed to terminate it.  Upper and lower
  566.      case are equivalent.
  567.      "Asking the question" means printing PROMPT in the echo area,
  568.      followed by the string `(y or n) '.  If the input is not one of
  569.      the expected answers (`y', `n', `SPC', `DEL', or something that
  570.      quits), the function responds `Please answer y or n.', and repeats
  571.      the request.
  572.      This function does not actually use the minibuffer, since it does
  573.      not allow editing of the answer.  It actually uses the echo area
  574.      (*note The Echo Area::.), which uses the same screen space as the
  575.      minibuffer.  The cursor moves to the echo area while the question
  576.      is being asked.
  577.      The answers and their meanings, even `y' and `n', are not
  578.      hardwired.  The keymap `query-replace-map' specifies them.  *Note
  579.      Search and Replace::.
  580.      In the following example, the user first types `q', which is
  581.      invalid.  At the next prompt the user types `y'.
  582.           (y-or-n-p "Do you need a lift? ")
  583.           
  584.           ;; After evaluation of the preceding expression,
  585.           ;;   the following prompt appears in the echo area:
  586.           ---------- Echo area ----------
  587.           Do you need a lift? (y or n)
  588.           ---------- Echo area ----------
  589.           
  590.           ;; If the user then types `q', the following appears:
  591.           ---------- Echo area ----------
  592.           Please answer y or n.  Do you need a lift? (y or n)
  593.           ---------- Echo area ----------
  594.           
  595.           ;; When the user types a valid answer,
  596.           ;;   it is displayed after the question:
  597.           ---------- Echo area ----------
  598.           Do you need a lift? (y or n) y
  599.           ---------- Echo area ----------
  600.      We show successive lines of echo area messages, but only one
  601.      actually appears on the screen at a time.
  602.  - Function: y-or-n-p-with-timeout PROMPT SECONDS DEFAULT-VALUE
  603.      Like `y-or-n-p', except that if the user fails to answer within
  604.      SECONDS seconds, this function stops waiting and returns
  605.      DEFAULT-VALUE.  It works by setting up a timer; see *Note Timers::.
  606.      The argument SECONDS may be an integer or a floating point number.
  607.  - Function: yes-or-no-p PROMPT
  608.      This function asks the user a question, expecting input in the
  609.      minibuffer.  It returns `t' if the user enters `yes', `nil' if the
  610.      user types `no'.  The user must type RET to finalize the response.
  611.      Upper and lower case are equivalent.
  612.      `yes-or-no-p' starts by displaying PROMPT in the echo area,
  613.      followed by `(yes or no) '.  The user must type one of the
  614.      expected responses; otherwise, the function responds `Please answer
  615.      yes or no.', waits about two seconds and repeats the request.
  616.      `yes-or-no-p' requires more work from the user than `y-or-n-p' and
  617.      is appropriate for more crucial decisions.
  618.      Here is an example:
  619.           (yes-or-no-p "Do you really want to remove everything? ")
  620.           
  621.           ;; After evaluation of the preceding expression,
  622.           ;;   the following prompt appears,
  623.           ;;   with an empty minibuffer:
  624.           ---------- Buffer: minibuffer ----------
  625.           Do you really want to remove everything? (yes or no)
  626.           ---------- Buffer: minibuffer ----------
  627.      If the user first types `y RET', which is invalid because this
  628.      function demands the entire word `yes', it responds by displaying
  629.      these prompts, with a brief pause between them:
  630.           ---------- Buffer: minibuffer ----------
  631.           Please answer yes or no.
  632.           Do you really want to remove everything? (yes or no)
  633.           ---------- Buffer: minibuffer ----------
  634. File: elisp,  Node: Multiple Queries,  Next: Minibuffer Misc,  Prev: Yes-or-No Queries,  Up: Minibuffers
  635. Asking Multiple Y-or-N Questions
  636. ================================
  637.    When you have a series of similar questions to ask, such as "Do you
  638. want to save this buffer" for each buffer in turn, you should use
  639. `map-y-or-n-p' to ask the collection of questions, rather than asking
  640. each question individually.  This gives the user certain convenient
  641. facilities such as the ability to answer the whole series at once.
  642.  - Function: map-y-or-n-p PROMPTER ACTOR LIST &optional HELP
  643.           ACTION-ALIST
  644.      This function, new in Emacs 19, asks the user a series of
  645.      questions, reading a single-character answer in the echo area for
  646.      each one.
  647.      The value of LIST specifies the objects to ask questions about.
  648.      It should be either a list of objects or a generator function.  If
  649.      it is a function, it should expect no arguments, and should return
  650.      either the next object to ask about, or `nil' meaning stop asking
  651.      questions.
  652.      The argument PROMPTER specifies how to ask each question.  If
  653.      PROMPTER is a string, the question text is computed like this:
  654.           (format PROMPTER OBJECT)
  655.      where OBJECT is the next object to ask about (as obtained from
  656.      LIST).
  657.      If not a string, PROMPTER should be a function of one argument
  658.      (the next object to ask about) and should return the question
  659.      text.  If the value is a string, that is the question to ask the
  660.      user.  The function can also return `t' meaning do act on this
  661.      object (and don't ask the user), or `nil' meaning ignore this
  662.      object (and don't ask the user).
  663.      The argument ACTOR says how to act on the answers that the user
  664.      gives.  It should be a function of one argument, and it is called
  665.      with each object that the user says yes for.  Its argument is
  666.      always an object obtained from LIST.
  667.      If the argument HELP is given, it should be a list of this form:
  668.           (SINGULAR PLURAL ACTION)
  669.      where SINGULAR is a string containing a singular noun that
  670.      describes the objects conceptually being acted on, PLURAL is the
  671.      corresponding plural noun, and ACTION is a transitive verb
  672.      describing what ACTOR does.
  673.      If you don't specify HELP, the default is `("object" "objects"
  674.      "act on")'.
  675.      Each time a question is asked, the user may enter `y', `Y', or SPC
  676.      to act on that object; `n', `N', or DEL to skip that object; `!'
  677.      to act on all following objects; ESC or `q' to exit (skip all
  678.      following objects); `.' (period) to act on the current object and
  679.      then exit; or `C-h' to get help.  These are the same answers that
  680.      `query-replace' accepts.  The keymap `query-replace-map' defines
  681.      their meaning for `map-y-or-n-p' as well as for `query-replace';
  682.      see *Note Search and Replace::.
  683.      You can use ACTION-ALIST to specify additional possible answers
  684.      and what they mean.  It is an alist of elements of the form `(CHAR
  685.      FUNCTION HELP)', each of which defines one additional answer.  In
  686.      this element, CHAR is a character (the answer); FUNCTION is a
  687.      function of one argument (an object from LIST); HELP is a string.
  688.      When the user responds with CHAR, `map-y-or-n-p' calls FUNCTION.
  689.      If it returns non-`nil', the object is considered "acted upon",
  690.      and `map-y-or-n-p' advances to the next object in LIST.  If it
  691.      returns `nil', the prompt is repeated for the same object.
  692.      If `map-y-or-n-p' is called in a command that was invoked using the
  693.      mouse--more precisely, if `last-nonmenu-event' (*note Command Loop
  694.      Info::.) is either `nil' or a list--then it uses a dialog box or
  695.      pop-up menu to ask the question.  In this case, it does not use
  696.      keyboard input or the echo area.  You can force use of the mouse
  697.      or use of keyboard input by binding `last-nonmenu-event' to a
  698.      suitable value around the call.
  699.      The return value of `map-y-or-n-p' is the number of objects acted
  700.      on.
  701. File: elisp,  Node: Minibuffer Misc,  Prev: Multiple Queries,  Up: Minibuffers
  702. Minibuffer Miscellany
  703. =====================
  704.    This section describes some basic functions and variables related to
  705. minibuffers.
  706.  - Command: exit-minibuffer
  707.      This command exits the active minibuffer.  It is normally bound to
  708.      keys in minibuffer local keymaps.
  709.  - Command: self-insert-and-exit
  710.      This command exits the active minibuffer after inserting the last
  711.      character typed on the keyboard (found in `last-command-char';
  712.      *note Command Loop Info::.).
  713.  - Command: previous-history-element N
  714.      This command replaces the minibuffer contents with the value of the
  715.      Nth previous (older) history element.
  716.  - Command: next-history-element N
  717.      This command replaces the minibuffer contents with the value of the
  718.      Nth more recent history element.
  719.  - Command: previous-matching-history-element PATTERN
  720.      This command replaces the minibuffer contents with the value of the
  721.      previous (older) history element that matches PATTERN (a regular
  722.      expression).
  723.  - Command: next-matching-history-element PATTERN
  724.      This command replaces the minibuffer contents with the value of
  725.      the next (newer) history element that matches PATTERN (a regular
  726.      expression).
  727.  - Function: minibuffer-prompt
  728.      This function returns the prompt string of the currently active
  729.      minibuffer.  If no minibuffer is active, it returns `nil'.
  730.  - Function: minibuffer-prompt-width
  731.      This function returns the display width of the prompt string of the
  732.      currently active minibuffer.  If no minibuffer is active, it
  733.      returns 0.
  734.  - Variable: minibuffer-setup-hook
  735.      This is a normal hook that is run whenever the minibuffer is
  736.      entered.  *Note Hooks::.
  737.  - Variable: minibuffer-exit-hook
  738.      This is a normal hook that is run whenever the minibuffer is
  739.      exited.  *Note Hooks::.
  740.  - Variable: minibuffer-help-form
  741.      The current value of this variable is used to rebind `help-form'
  742.      locally inside the minibuffer (*note Help Functions::.).
  743.  - Function: active-minibuffer-window
  744.      This function returns the currently active minibuffer window, or
  745.      `nil' if none is currently active.
  746.  - Function: minibuffer-window &optional FRAME
  747.      This function returns the minibuffer window used for frame FRAME.
  748.      If FRAME is `nil', that stands for the current frame.  Note that
  749.      the minibuffer window used by a frame need not be part of that
  750.      frame--a frame that has no minibuffer of its own necessarily uses
  751.      some other frame's minibuffer window.
  752.  - Function: window-minibuffer-p WINDOW
  753.      This function returns non-`nil' if WINDOW is a minibuffer window.
  754.    It is not correct to determine whether a given window is a
  755. minibuffer by comparing it with the result of `(minibuffer-window)',
  756. because there can be more than one minibuffer window if there is more
  757. than one frame.
  758.  - Function: minibuffer-window-active-p WINDOW
  759.      This function returns non-`nil' if WINDOW, assumed to be a
  760.      minibuffer window, is currently active.
  761.  - Variable: minibuffer-scroll-window
  762.      If the value of this variable is non-`nil', it should be a window
  763.      object.  When the function `scroll-other-window' is called in the
  764.      minibuffer, it scrolls this window.
  765.    Finally, some functions and variables deal with recursive minibuffers
  766. (*note Recursive Editing::.):
  767.  - Function: minibuffer-depth
  768.      This function returns the current depth of activations of the
  769.      minibuffer, a nonnegative integer.  If no minibuffers are active,
  770.      it returns zero.
  771.  - User Option: enable-recursive-minibuffers
  772.      If this variable is non-`nil', you can invoke commands (such as
  773.      `find-file') that use minibuffers even while in the minibuffer
  774.      window.  Such invocation produces a recursive editing level for a
  775.      new minibuffer.  The outer-level minibuffer is invisible while you
  776.      are editing the inner one.
  777.      This variable only affects invoking the minibuffer while the
  778.      minibuffer window is selected.   If you switch windows while in the
  779.      minibuffer, you can always invoke minibuffer commands while some
  780.      other window is selected.
  781.    If a command name has a property `enable-recursive-minibuffers' that
  782. is non-`nil', then the command can use the minibuffer to read arguments
  783. even if it is invoked from the minibuffer.  The minibuffer command
  784. `next-matching-history-element' (normally `M-s' in the minibuffer) uses
  785. this feature.
  786. File: elisp,  Node: Command Loop,  Next: Keymaps,  Prev: Minibuffers,  Up: Top
  787. Command Loop
  788. ************
  789.    When you run Emacs, it enters the "editor command loop" almost
  790. immediately.  This loop reads key sequences, executes their definitions,
  791. and displays the results.  In this chapter, we describe how these things
  792. are done, and the subroutines that allow Lisp programs to do them.
  793. * Menu:
  794. * Command Overview::    How the command loop reads commands.
  795. * Defining Commands::   Specifying how a function should read arguments.
  796. * Interactive Call::    Calling a command, so that it will read arguments.
  797. * Command Loop Info::   Variables set by the command loop for you to examine.
  798. * Input Events::    What input looks like when you read it.
  799. * Reading Input::       How to read input events from the keyboard or mouse.
  800. * Waiting::             Waiting for user input or elapsed time.
  801. * Quitting::            How `C-g' works.  How to catch or defer quitting.
  802. * Prefix Command Arguments::    How the commands to set prefix args work.
  803. * Recursive Editing::   Entering a recursive edit,
  804.                           and why you usually shouldn't.
  805. * Disabling Commands::  How the command loop handles disabled commands.
  806. * Command History::     How the command history is set up, and how accessed.
  807. * Keyboard Macros::     How keyboard macros are implemented.
  808. File: elisp,  Node: Command Overview,  Next: Defining Commands,  Up: Command Loop
  809. Command Loop Overview
  810. =====================
  811.    The first thing the command loop must do is read a key sequence,
  812. which is a sequence of events that translates into a command.  It does
  813. this by calling the function `read-key-sequence'.  Your Lisp code can
  814. also call this function (*note Key Sequence Input::.).  Lisp programs
  815. can also do input at a lower level with `read-event' (*note Reading One
  816. Event::.) or discard pending input with `discard-input' (*note Event
  817. Input Misc::.).
  818.    The key sequence is translated into a command through the currently
  819. active keymaps.  *Note Key Lookup::, for information on how this is
  820. done.  The result should be a keyboard macro or an interactively
  821. callable function.  If the key is `M-x', then it reads the name of
  822. another command, which it then calls.  This is done by the command
  823. `execute-extended-command' (*note Interactive Call::.).
  824.    To execute a command requires first reading the arguments for it.
  825. This is done by calling `command-execute' (*note Interactive Call::.).
  826. For commands written in Lisp, the `interactive' specification says how
  827. to read the arguments.  This may use the prefix argument (*note Prefix
  828. Command Arguments::.) or may read with prompting in the minibuffer
  829. (*note Minibuffers::.).  For example, the command `find-file' has an
  830. `interactive' specification which says to read a file name using the
  831. minibuffer.  The command's function body does not use the minibuffer;
  832. if you call this command from Lisp code as a function, you must supply
  833. the file name string as an ordinary Lisp function argument.
  834.    If the command is a string or vector (i.e., a keyboard macro) then
  835. `execute-kbd-macro' is used to execute it.  You can call this function
  836. yourself (*note Keyboard Macros::.).
  837.    To terminate the execution of a running command, type `C-g'.  This
  838. character causes "quitting" (*note Quitting::.).
  839.  - Variable: pre-command-hook
  840.      The editor command loop runs this normal hook before each command.
  841.      At that time, `this-command' contains the command that is about to
  842.      run, and `last-command' describes the previous command.  *Note
  843.      Hooks::.
  844.  - Variable: post-command-hook
  845.      The editor command loop runs this normal hook after each command
  846.      (including commands terminated prematurely by quitting or by
  847.      errors), and also when the command loop is first entered.  At that
  848.      time, `this-command' describes the command that just ran, and
  849.      `last-command' describes the command before that.  *Note Hooks::.
  850.    Quitting is suppressed while running `pre-command-hook' and
  851. `post-command-hook'.  If an error happens while executing one of these
  852. hooks, it terminates execution of the hook, but that is all it does.
  853. File: elisp,  Node: Defining Commands,  Next: Interactive Call,  Prev: Command Overview,  Up: Command Loop
  854. Defining Commands
  855. =================
  856.    A Lisp function becomes a command when its body contains, at top
  857. level, a form that calls the special form `interactive'.  This form
  858. does nothing when actually executed, but its presence serves as a flag
  859. to indicate that interactive calling is permitted.  Its argument
  860. controls the reading of arguments for an interactive call.
  861. * Menu:
  862. * Using Interactive::     General rules for `interactive'.
  863. * Interactive Codes::     The standard letter-codes for reading arguments
  864.                              in various ways.
  865. * Interactive Examples::  Examples of how to read interactive arguments.
  866.